package com.blb.thread;

public class JoinDemo {

    static Thread thread1 = null;
    static Thread thread2 = null;

    public static void main(String[] args) {
        thread1 = new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                System.out.println(Thread.currentThread().getName() + "--->" + i);
                if(i == 5){
                    try {
                        //合并thread2线程
                        thread2.join(5000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
        thread2 = new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                System.out.println(Thread.currentThread().getName() + "--->" + i);
                if(i == 5){
                    try {
                        //合并thread1线程
                        thread1.join();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
        thread1.setName("老李");
        thread2.setName("小李");
        thread1.setPriority(Thread.MIN_PRIORITY);
        thread2.setPriority(Thread.MAX_PRIORITY);
        thread1.start();
        thread2.start();
    }
}
